package com.utilmodule;

import android.app.ActivityManager;
import android.content.Context;
import android.text.TextUtils;

import java.util.List;

/**
 * Created by liuhongyuan on 2017/6/11
 **/

public class Utils {
    /**
     * 判断一个Activity是否正在运行
     *
     * @param context
     * @return
     */

    public static boolean isClsRunning(String pkg, String cls, Context context) {

        ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

        List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(1);

        ActivityManager.RunningTaskInfo task = tasks.get(0);

        if (task != null) {

            return TextUtils.equals(task.topActivity.getPackageName(), pkg) && TextUtils.equals(task.topActivity.getClassName(), cls);

        }

        return false;
    }
}
